import 'package:flutter/material.dart';

enum Animal {
  cat(
    legs: 4,
    moreInfoUrl: 'https://en.wikipedia.org/wiki/Cat',
  ),

  kangaroo(
    legs: 2,
    moreInfoUrl: 'https://en.wikipedia.org/wiki/Kangaroo',
  );

  final int legs;
  final String moreInfoUrl;
  const Animal({
    required this.legs,
    required this.moreInfoUrl,
  });

  @override
  String toString() => {
        'legs': legs,
        'moreInfoUrl': moreInfoUrl,
      }.toString();
}

void testIt() {
  for (final animal in Animal.values) {
    print(animal);
  }
  // prints the followings
  // {legs: 4, moreInfoUrl: https://en.wikipedia.org/wiki/Cat}
  // {legs: 2, moreInfoUrl: https://en.wikipedia.org/wiki/Kangaroo}
}

enum ResultType { value, error }

@immutable
class Result<T, E> {
  final T? value;
  final E? error;
  final ResultType type;
  const Result.error({required E input})
      : error = input,
        value = null,
        type = ResultType.error;
  const Result.value({required T input})
      : value = input,
        error = null,
        type = ResultType.value;
  E get requireError => error!;
  T get requireValue => value!;

  @override
  String toString() {
    switch (type) {
      case ResultType.value:
        return 'Value = ${requireValue.toString()}';
      case ResultType.error:
        return 'Error = ${requireError.toString()}';
    }
  }
}

void testIt2() {
  Result.value(input: "10");

  Result.error(input: "404");
}
